// 公共的请求
var timestamp = new Date().getTime(); //时间戳

const request = function(options) {
	options.url = options.url;
	try {
		const token = uni.getStorageSync('token');
		const user_id = uni.getStorageSync('user_id');
		console.log(token, user_id);
		if (token && user_id) {
			options.header = {
				'W-Program-Code': 1101,
				'W-App-Id': 1003,
				'W-Auth-Timestamp': timestamp,
				'W-Lang': 'zh_cn',
				'W-Release-Version': '1.0.0',
				'W-Token': token,
				'W-Uid': user_id,
				'W-Auth-Key': '',
				'W-Auth-Signature': '',
			}

		} else {
			uni.reLaunch({
				url: 'pages/login/login'
			});
			return;
		}
	} catch (err) {
		console.log(err)
	}
	// response处理
	// options.complete = (response) => {
	// 	if (options.url != "http://wechat.wanshunzhongda.com/driver/location/uploadLocation") {
	// 		if (response.data.code == 20001 || response.data.code == 30001) {
	// 			uni.reLaunch({
	// 				url: '/pages/login/login?message=' + response.data.message
	// 			});
	// 			// console.log(30001)
	// 			return;
	// 		} else {
	// 			return;
	// 		}
	// 	}
	// }
	return uni.request(options);

}

export default request;
